package com.luzhikun.CRMProject;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class Test3Servlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("application/json;charset=UTF-8");
        City city=new City(1,"吴杰",3);
        City city1=new City(2,"傻逼",1);

        //"{"city":{"id":1,"name":"吴杰","provinceid":3},"city1":{"id":1,"name":"傻逼","provinceid":1}}"
        // 创建一个json格式的数据                                           "+city.getId()+"
        String json="{\"city\":{\"id\":\""+city.getId()+"\",\"name\":\""+city.getName()+"\",\"provinceid\":"+city.getProvinceId()
                +"\"},\"city1\":{\"id\":"+city1.getId()+",\"name\":\""+city1.getName()+ "\",\"provinceid\":"+city1.getProvinceId()+"}}";
            System.out.println(json);
//        String json="{\"name\":\"吴杰\",\"age\":\"12\",\"属性\":\"傻逼\"}";
          response.getWriter().println(json);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
